<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>
<div th:fragment="pzcurmainDetailBudget">
    <div id="pzcurmainDetailBudget_toolbar" class="m-l-xs toolbar">
        <button class="btn btn-sm btn-primary" type="button"
                onclick="pzcurmainDetailBudgetListObj.addOrUpdateHandle()"><i
                class="fa fa-plus"></i>&nbsp;新增
        </button>
    </div>
    <table id="pzcurmainDetailBudget_table" class="table table-striped"></table>
    <!--    弹窗：预算编辑-->
    <div th:replace="web/pz/cur/pzcurmain-detail-budget-edit::pzcurmainDetailBudgetEdit"></div>
    <script type="text/javascript">
        $(function () {
            pzcurmainDetailBudgetListObj.myTable = $('#pzcurmainDetailBudget_table').bootstrapTable({
                toolbar: '#pzcurmainDetailBudget_toolbar',
                formatNoMatches: function () {  //没有匹配的结果
                    return '暂无数据';
                },
                columns: [{
                    title: '预算部门',
                    field: 'deptName',
                    width: 150,
                }, {
                    title: '预算项目',
                    field: 'projectName',
                    width: 150,
                }, {
                    title: '经济分类',
                    field: 'cateName'
                }, {
                    title: '申请金额',
                    field: 'money',
                    formatter: function (value, row, index) {
                        return $.moneyFormat(value);
                    }
                }, {
                    title: '费用说明',
                    field: 'remark'
                }, {
                    title: '收款信息',
                    field: 'receivables',
                    visible: false,
                    formatter: function (value, row, index) {
                        var values = [];
                        values.push('名称:' + (row.receivablesName ? row.receivablesName : ''));
                        values.push('账号:' + (row.receivablesAccount ? row.receivablesAccount : ''));
                        values.push('开户行:' + (row.receivablesBank ? row.receivablesBank : ''));
                        return values.join("<br/>");
                    }
                }, {
                    title: '操作',
                    width: 160,
                    events: {
                        'click .edit': function (e, value, row, index) {
                            pzcurmainDetailBudgetListObj.addOrUpdateHandle(row.id)
                        },
                        'click .trash': function (e, value, row, index) {
                            pzcurmainDetailBudgetListObj.deleteHandle(row.id)
                        }
                    },
                    formatter: function (value, row, index) {
                        var opers = [];
                        opers.push(`<a class="edit btn btn-white btn-bitbucket text-success" data-toggle="tooltip" title="编辑">
                                    <i class="fa fa-edit"></i>
                                </a>`)
                        opers.push(`<a class="trash btn btn-white btn-bitbucket text-success" data-toggle="tooltip" title="删除">
                                    <i class="fa fa-trash"></i>
                                </a>`)
                        return opers.join('');
                    }
                }],
                responseHandler: function (res) {
                    return res.data;
                },
                onLoadSuccess: function (data) {
                    $('[data-toggle="tooltip"]').tooltip()
                }
            });
        })
        var pzcurmainDetailBudgetListObj = new Object({
            applyType: undefined,
            mainId: undefined,
            depts: undefined,
            myTable: undefined,
            addOrUpdateHandle: function (id) {
                pzcurmainDetailBudgetEditObj.init(id);
            },
            deleteHandle: function (id) {
                $.mySwalConfirm("将删除明细信息，确认吗？", function () {
                    $.myDelete({
                        url: `/pz/cur/pzbudget/budget/${pzcurmainDetailBudgetListObj.mainId}`,
                        dataType: 'json',
                        data: [id],
                        success: function (data) {
                            if (data && data.code == 0) {
                                toastr.success(data.msg, '操作提示')
                                pzcurmainDetailBudgetListObj.refreshDataList();
                            } else {
                                toastr.error(data.msg, '操作失败')
                            }
                        }
                    })
                });
            },
            refreshDataList: function () {
                this.myTable.bootstrapTable('refresh');
            },
            init: function (applyType, mainId, depts) {
                pzcurmainDetailBudgetListObj.applyType = applyType;
                pzcurmainDetailBudgetListObj.mainId = mainId;
                pzcurmainDetailBudgetListObj.depts = depts;
                this.myTable.bootstrapTable('refresh', {
                    url: `/pz/cur/pzbudget/list/${mainId}`
                });
                if (applyType == 'spending') {
                    this.myTable.bootstrapTable('hideColumn', 'receivables');
                } else {
                    this.myTable.bootstrapTable('showColumn', 'receivables');
                }
            }
        });
    </script>
</div>
</body>
</html>